#include "Mutex.h"

using namespace yazi::thread;

Mutex::Mutex(){
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
    pthread_mutex_init(&m_mut, &attr);
    pthread_mutexattr_destroy(&attr);
}

Mutex::~Mutex(){
    pthread_mutex_destroy(&m_mut);
}

int Mutex::lock(){
    return pthread_mutex_lock(&m_mut);
}

int Mutex::trylock(){
    return pthread_mutex_trylock(&m_mut);
}

int Mutex::unlock(){
    return pthread_mutex_unlock(&m_mut);
}